<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('修改兼任人员信息')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<style>
    .select2 {
        width: 100% !important;
    }
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-retire-edit" AUTOCOMPLETE="OFF">
        <input name="id" id="id" type="hidden" th:value="${register.id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">工号：</label>
            <div class="col-sm-8">
                <input class="form-control" id="badge" type="text" th:value="${register.badge}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">姓名：</label>
            <div class="col-sm-8">
                <input class="form-control" id="name" type="text" th:value="${register.name}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">公司名称：</label>
            <div class="col-sm-8">
                <input class="form-control" id="compName" type="text" th:value="${register.compName}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">部门名称：</label>
            <div class="col-sm-8">
                <input class="form-control" id="depName" type="text" th:value="${register.depName}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">岗位名称：</label>
            <div class="col-sm-8">
                <input class="form-control" id="jobName" type="text" th:value="${register.jobName}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">员工状态：</label>
            <div class="col-sm-8">
                <input class="form-control" id="empStatusName" type="text" th:value="${register.empStatusName}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">在岗状态：</label>
            <div class="col-sm-8">
                <input class="form-control" id="jobStatusName" type="text" th:value="${register.jobStatusName}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">入职日期：</label>
            <div class="col-sm-8">
                <input class="form-control" id="joinDate" type="text" th:value="${register.joinDate}"
                       readonly="readonly"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">兼任公司名称：</label>
            <div class="col-sm-8">
                <select name="partCompIDTitle" id="partCompIDTitle" class="form-control" onchange="changComp()">
                    <option value="">请选择</option>
                    <option th:each="comp : ${comp}" th:text="${comp.title}"
                            th:value="${comp.compid}"
                            th:selected="${register.partCompIDTitle==comp.title ? true : false}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">兼任部门名称：</label>
            <div class="col-sm-8">
                <select name="partDepIDTitle" id="partDepIDTitle" class="form-control" onchange="changJob()">
                    <option value="">请选择</option>
                </select>
                <input id="depid" type="hidden" th:value="${register.partDepIDTitle}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">兼任工作岗位：</label>
            <div class="col-sm-8">
                <select name="partJobIDTitle" id="partJobIDTitle" class="form-control">
                    <option value="">请选择</option>
                </select>
                <input id="jobid" type="hidden" th:value="${register.partJobIDTitle}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">兼任岗位级别：</label>
            <div class="col-sm-8">
                <select name="partjobgradeTitle" id="partjobgradeTitle" class="form-control">
                    <option value="">请选择</option>
                    <option th:each="jobGrade : ${jobGrade}" th:text="${jobGrade.title}"
                            th:value="${jobGrade.id}"
                            th:selected="${register.partjobgradeTitle==jobGrade.title ? true : false}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">兼任原因：</label>
            <div class="col-sm-8">
                <input class="form-control" name="reason" id="reason" type="text" th:value="${register.reason}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">兼任开始日期：</label>
            <div class="col-sm-8">
                <input class="form-control" name="beginDate" id="beginDate" type="text"
                       th:value="${register.beginDate}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">备注：</label>
            <div class="col-sm-8">
                <input class="form-control" name="remark" id="remark" type="text" th:value="${register.remark}"/>
            </div>
        </div>
    </form>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>

<script th:inline="javascript">

    var prefix = ctx + "changeManage/EmpConcurrentlyManage";

    $(function () {
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#beginDate',
                type: 'date'
            });
        });
        changComp();
        changJob();
    });

    function changComp() {
        var partCompIDTitle = $("#partCompIDTitle").val();
        var depid = $("#depid").val();
        $.ajax({
            async: false,
            url: prefix + "/changComp",
            data: {
                "partCompIDTitle": partCompIDTitle
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                var str = "";
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        str += '<option value=' + data[i].depid;
                        if (depid == data[i].title) {
                            str += ' selected="true" ';
                        }
                        str += '>' + data[i].title + '</option>'
                    }
                    $("#partDepIDTitle").html(str);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function changJob() {
        var partDepIDTitle = $("#partDepIDTitle").val();
        var jobid = $("#jobid").val();
        $.ajax({
            async: false,
            url: prefix + "/changJob",
            data: {
                "partDepIDTitle": partDepIDTitle
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                var str = "";
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        str += '<option value=' + data[i].jobid;
                        if (jobid == data[i].title) {
                            str += ' selected="true" ';
                        }
                        str += '>' + data[i].title + '</option>'
                    }
                    $("#partJobIDTitle").html(str);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-retire-edit").serializeArray();
            var partCompIDTitle = $("#partCompIDTitle").val();
            var partDepIDTitle = $("#partDepIDTitle").val();
            var partJobIDTitle = $("#partJobIDTitle").val();
            var reason = $("#reason").val();
            var beginDate = $("#beginDate").val();
            if (partCompIDTitle == "" || partCompIDTitle == null) {
                $.modal.alertWarning("请选择兼任公司!");
                return;
            }
            if (partDepIDTitle == "" || partDepIDTitle == null) {
                $.modal.alertWarning("请选择兼任部门!");
                return;
            }
            if (partJobIDTitle == "" || partJobIDTitle == null) {
                $.modal.alertWarning("请选择兼任工作岗位!");
                return;
            }
            if (reason == "" || reason == null) {
                $.modal.alertWarning("请输入兼任原因!");
                return;
            }
            if (beginDate == "" || beginDate == null) {
                $.modal.alertWarning("请选择兼任开始日期!");
                return;
            }
            $.operate.save(prefix + "/editRegister", data);
        }
    }

</script>


</body>
</html>